package com.ymy.springboot.service.impl;

import com.ymy.springboot.dataobject.ProductInfo;
import com.ymy.springboot.enums.ProductStatusEnum;
import com.ymy.springboot.repository.ProductInfoRepository;
import com.ymy.springboot.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;


import java.util.List;

/**
 * @author ymy.hadoop
 * @date 2019/5/13 上午11:04
 */
@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductInfoRepository productInfoRepository;

    @Override
    public ProductInfo findOne(String productId) {
       return productInfoRepository
               .findOne(productId);
    }

    /***
     * 找出已上架的商品
     * @return
     */
    @Override
    public List<ProductInfo> findUpAll() {
        return productInfoRepository
                .findByProductStatus(ProductStatusEnum.UP.getCode());
    }

    /**
     * 注意Pageable类不要倒错包了！！！，是否倒错包，需要从Service的接口里面开始排查
     * @param pageable
     * @return
     */
    @Override
    public Page<ProductInfo> findAll(Pageable pageable) {
        return productInfoRepository.findAll(pageable);
    }

    @Override
    public ProductInfo save(ProductInfo productInfo) {
        return productInfoRepository.save(productInfo);
    }
}
